package com.admin.education.controllers.api.v1;

import com.admin.education.common.exceptions.BadRequestException;
import com.admin.education.common.response.IResponseMessage;
import com.admin.education.common.response.ResponseMessageWithData;
import com.admin.education.common.response.Result;
import com.admin.education.dataTransferObject.PageResponse;
import com.admin.education.dataTransferObject.ServicesExcuteResult;
import com.admin.education.dataTransferObject.userRecord.Request.QueryUserRecordRequest;
import com.admin.education.dataTransferObject.userRecord.UserRecordTransfer;
import com.admin.education.services.Interfaces.IClassService;
import com.admin.education.services.Interfaces.IUserRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.concurrent.Callable;

@RestController
@RequestMapping("/v1/userRecords")
public class UserRecordController {
    @Autowired
    private IUserRecordService userRecordService;
    @GetMapping("")
    public Callable<IResponseMessage> queryUserRecord(@Valid QueryUserRecordRequest queryUserRecordRequest){
        return ()->{
            IResponseMessage responseMessage = null;

            ServicesExcuteResult<PageResponse<UserRecordTransfer>> result = this.userRecordService.queryUserRecord(queryUserRecordRequest);

            if(result.isSuccess()){
                responseMessage = new ResponseMessageWithData<>(Result.Success,result.getData());
            }
            else{
                throw new BadRequestException(result.getErrorMessage());
            }
            return responseMessage;
        };
    }
}